<template>
    <div class="main">
        <eagle-input label="企业名称" v-model="CompanyName" name="area" required />
        <eagle-input label="行业" v-model="IndustryName" name="area" placeholder="请选择" @click="chooseIndustry()"
            autosize=true type="textarea" rows="1" required />
        <eagle-input label="所在地区" v-model="Address" name="area" placeholder="请选择" required @click="showAddress"/>
        <eagle-input label="企业信息配置模板" v-model="Template.ConfigName" name="area"  @click="show = true" readonly />
        <div class="btn_submit">
            <van-button class="br-5" block type="info" @click="save">
                保存
            </van-button>
        </div>
        <eagle-popup v-model="show" title="企业信息配置模板" round :popStyle="{ height: '80%', width: '50%' }">
            <eagle-list>
                <van-cell v-for="item in TemplateList" :key="item.ConfigCode" :title="item.ConfigName"
                    @click="chooseTemplate(item)" />
            </eagle-list>
        </eagle-popup>
        <van-popup v-model="showAreaPop" position="bottom" :style="{ height: '60%' }">
      <van-area title="选择地区" :area-list="areaList" value="110101" :columns-num="2"
        :columns-placeholder="['请选择', '请选择', '请选择']" @confirm="handleSelect" />
    </van-popup>

    </div>

</template>
<script>
import { getTemplateList } from '@/api/base';
import { areaList } from '@vant/area-data';
export default {
    data() {
        return {
            CompanyName: "",
            Industry: "",
            IndustryName: "",
            Template: {},
            TemplateList: [],
            Address: "",
            show: false,
            areaList: areaList,
            showAreaPop: false,
        };
    },
    created() {
        getTemplateList().then((res) => {
            this.TemplateList = res.data.Data
        })
    },
    activated() {
        console.log("activated" + this.$store.state.Industry)
        this.Industry = this.$store.state.Industry
        this.IndustryName = this.$store.state.IndustryName

    },
    methods: {
        chooseIndustry() {
            this.$router.push({
                path: "BaseInfo/Industry",
                query: {

                },
            });
        },
        showAddress(){
            this.showAreaPop=true
        },
            //地区选择 确认
    handleSelect(value) {
      let addressNames = []
      value.map(item => {
        if (item.name) {
          addressNames.push(item.name)
        }
      })
      this.Address=addressNames.join('/')

      this.showAreaPop = false
 
  
    },
        chooseTemplate(item) {
            this.Template = item
            this.show = false
        },
        save() {
            if (this.CompanyName == "") {
                this.$toast("企业名称不能为空")
                return
            }
            if (this.Industry == "") {
                this.$toast("行业不能为空")
                return
            }
            if (this.Address == "") {
                this.$toast("地址不能为空")
                return
            }
            // if (this.Template.ConfigCode == ""||this.Template.ConfigCode == null) {
            //     this.$toast("模板不能为空")
            //     return
            // }
            let params = {}
            params.CompanyName = this.CompanyName
            params.ApplyProfession = this.Industry
            params.IndustryName = this.IndustryName
            params.ApplyArea = this.Address
            params.ConfigCode = this.Template.ConfigCode
            this.$axios.post("/UserCompany/AddCompanyByName", params).then(res => {
                this.$store.commit('setIndustry', "")
                this.$store.commit('setIndustryName', "")
                this.$router.push("/BaseInfo?CompanyCode=" + res.data.CompanyCode);
            })


        }

    }
}

</script>
<style lang="less" scoped></style>